// page/index/index.js
const app = getApp()
var isCheckIn = false //是否入住
var isCheckOut = false //是否离开
var checkInIndexMonth = 0 //入住点击月 index
var checkInIndexDay = 0 //入住点击天 index
var checkInRe = '' //选择入住日期
var con = 0 // 选择日期的点击次数
var startDate = '' //入住日期的回传
var endDate = '' //离开日期的回传
var indexStart = 0
var overnight = 1 //1：过夜； 0：不过夜
const timeChange = require('../../utils/timeChange.js')
Page({

  /**
   * 页面的初始数据
   *
   */
  data: {
    arr: [],
    sysW: null,
    lastDay: null,
    firstDay: null,
    weekArr: ['日', '一', '二', '三', '四', '五', '六'],
    year: null,
    calendarNum: 6,
    isRoomList: false,
    calendarListIndex: 0
  },

  onLoad: function(options) {
    this.getIntentData(options)

    var res = wx.getSystemInfoSync();
    this.setData({
      sysW: res.windowHeight / 12, //更具屏幕宽度变化自动设置宽度
      marLet: this.data.firstDay,
      arr: this.data.arr,
      sysH: res.windowHeight
    });
    if (this.data.isReserve == 1) { //价格日历
      this.connectNetForDate()

    } else {
      this.dateData();
      this.dateSelected();
    }



  },
  /**
   * 数据传递
   */
  getIntentData(options) {
    isCheckIn = false
    isCheckOut = false
    con = 0
    if (options.isReserve == 1) { //价格日历
      var sriId = options.roomId
      startDate = options.startTime
      endDate = options.endTime
      var overnight = options.whetherOvernight
      this.setData({
        isReserve: 1,
        sriId: sriId,
        overnight: overnight
      })
    } else { //其他日历
      this.setData({
        isRoomList: options.isRoomList,
        isReserve: 0
      })
      if (this.data.isRoomList == 'false') {
        startDate = options.startTime
        endDate = options.endTime
      } else {
        startDate = options.startTime
        endDate = options.endTime
      }

      console.log("   其他日历 ：  " + startDate + '   :   ' + endDate)
    }

  },


  /**
   * 请求价格日历数组 
   */
  connectNetForDate() {
    wx.showLoading({
      title: '加载中...',
    })
    var that = this
    console.log(app.baseNet + 'roomInfo/queryRoomPriceCalendar?sriRid=' + that.data.sriId)
    wx.request({
      url: app.baseNet + 'roomInfo/queryRoomPriceCalendar',
      data: {
        sriRid: that.data.sriId
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success(res) {
        if (res.statusCode) { //请求数据成功
          var dataList = res.data
          if (dataList.messcode == '001') {
            var list = dataList.roomPriceCalendarList
            that.setData({
              calendarList: list
            })
            that.dateData();
            that.setCalendarList()
            that.dateSelected()
          }

        }
      }
    })

  },

  /**
   * 设置价格日历数据
   */
  setCalendarList() {
    var that = this
    var dateList = this.data.calendarList //日历价格集合
    let dayStart = new Date().getDate() //当天


    var yearStart = parseInt(dateList[0].time.split('-')[0]) //首月年份
    var yearEnd = parseInt(dateList[dateList.length - 1].time.split('-')[0]) //最后一个月年份

    let month = new Date().getMonth() //当前前一个月份
    var monthEnd = parseInt(dateList[dateList.length - 1].time.split('-')[1]) //当前月份
    var monthDate = this.data.date.length

    var innMonthMax = 0
    if (yearStart == yearEnd) { //当前年份日历价格
      innMonthMax = monthEnd - month
    } else {
      innMonthMax = 12 - month + monthEnd
    }

    if (innMonthMax > monthDate) {
      innMonthMax = monthDate
    }

    var dayEnd = parseInt(dateList[dateList.length - 1].time.split('-')[2]) //当前最后一天遍历
    for (var i = 0; i < innMonthMax; i++) { //循环日历集合  循环月
      var indexK = 0;
      if (i == 0) {
        indexK = dayStart - 1
      } else {
        indexK = 0
      }
      var ddEnd = this.data.date[i].length
      if (i == innMonthMax - 1) {
        ddEnd = dayEnd
      } else {
        ddEnd = that.data.date[i].length
      }
      for (var k = indexK; k < ddEnd; k++) { //循环日
        var dateAll = this.data.date[i][k].re // 获取日期格式字符串 yy-mm-dd
        var datePrice = 'date[' + i + '].[' + k + '].price' //日期价格的设置
        var isCheckRoom = 'date[' + i + '].[' + k + '].isCheckRoom' //日期是否有房可以预定
        var isPriceStyle = 'date[' + i + '].[' + k + '].isPriceStyle' //日期价格的样式
        console.log(dateAll)
        // for (var j = indexStart; j < dateList.length; j++) { //日历价格数组
        //   var time = dateList[j].time
        //   var price = dateList[j].price
        //   var num = dateList[j].nums
        //   console.log(num)
        //   console.log('日期遍历：  ' + time + "  :   " + dateAll + "    :  " + (time == dateAll))
        //   if (time == dateAll) { //日期遍历
        //     indexStart = j
        //     that.setData({
        //       [datePrice]: num >= 1 ? price : '已租',
        //       [isCheckRoom]: num >= 1 ? true : false,
        //       [isPriceStyle]: num >= 1 ? 2 : 3
        //     })
        //     console.log('价格 :  ' + that.data.date)
        //   }
        // }

        var j = that.data.calendarListIndex
        var timeDay = dateList[j].time
        var price = dateList[j].price
        var num = dateList[j].nums
        console.log(j + " :   " + timeDay + "   :  " + dateAll)
        if (timeDay != 'undefined' && (timeDay == dateAll || j >= 1)) {
          var ind = j;
          console.log('ind : ' + ind)
          that.setData({
            [datePrice]: num >= 1 ? '￥' + price : '已租',
            [isCheckRoom]: num >= 1 ? true : false,
            [isPriceStyle]: num >= 1 ? 2 : 3,
            calendarListIndex: ind < (that.data.calendarList.length - 1) ? ind + 1 : ind
          })

        } else if (timeDay == 'undefined') {
          break
        }
        // console.log(dayEnd + " #############  " + i + "     day : " + j)
      }
    }
    wx.hideLoading()
  },

  /**
   * 日历数据
   */
  dateData: function() {
    let dataAll = [] //总日历数据
    let dataAll2 = [] //总日历数据
    let dataMonth = [] //月日历数据

    let date = new Date //当前日期
    let year = date.getFullYear() //当前年
    let week = date.getDay(); //当天星期几
    let weeks = []
    let month = date.getMonth() + 1 //当前月份
    let day = date.getDate() //当天
    console.log("当天日期： " + day)
    console.log("当天周期： " + week)

    let monthCount = 6 //一共显示多少月份

    let dayscNow = 0 //计数器
    let monthList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] //月份列表
    let nextMonthList = [] //需要跨年的下一年月份列表

    let nowMonthList = [] //本年剩余年份 

    //需要展示的日历月份列表
    var key = 0;
    for (var i = 0; i < monthCount; i++) {
      var dd = month + i;
      console.log('i : ' + i)
      if (dd < 13) {
        nowMonthList.push(dd)
        key = i;
        console.log('key: ' + key)
      } else {
        console.log("monthList[i - key]:" + monthList[i - key - 1])
        console.log('i - key : ' + (i - key))
        nextMonthList.push(monthList[i - key - 1])
      }
    }

    console.log('now: ' + nowMonthList)
    console.log('next: ' + nextMonthList)


    let yearList = [year] //年份最大可能
    if (month + monthCount > 13) {
      yearList.push(year + 1)
    }

    let leapYear = function(Year) { //判断是否闰年 
      if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)) { //闰年
        return (true);
      } else { //平年
        return (false);
      }
    }


    for (let i = 0; i < yearList.length; i++) { //遍历年
      let mList
      if (yearList[i] == year) { //判断当前年份
        mList = nowMonthList
      } else { //下一年
        mList = nextMonthList
      }
      console.log("mList  :   ————  " + mList)

      for (let j = 0; j < mList.length; j++) { //循环月份
        dataMonth = []
        //12个月份的天数的数组
        let t_days = [31, 28 + leapYear(yearList[i]), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        let t_days_thisYear = []
        if (yearList[i] == year) { //当前年份的每个月的天数集合
          for (let m = 0; m < nowMonthList.length; m++) {
            t_days_thisYear.push(t_days[mList[m] - 1])
          }
          t_days = t_days_thisYear
        } else { //下一个年份的每个月的天数集合
          t_days = [31, 28 + leapYear(yearList[i]), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        }
        var months = ''
        if (mList[j] < 10) {
          months = '0' + mList[j]
        } else {
          months = mList[j]
        }
        console.log("months  :   ————  " + months)

        for (let k = 0; k < t_days[j]; k++) { //循环每天
          let nowData
          let days = k + 1
          if (days < 10) {
            days = "0" + days
          }

          if (yearList[i] == year && mList[j] == month) { //判断当年当月 ，
            if (k + 1 > day) { // 当天以后
              nowData = {
                year: yearList[i],
                month: months,
                day: k + 1,
                date: yearList[i] + "" + months + days,
                selected: 0,
                re: yearList[i] + "-" + months + "-" + days,
                dd: k + 1,
                price: '', //预定房子价格 
                isCheckRoom: true, //是否有房子可以预定
                isPriceStyle: 1 //价格显示的样式
              }
            } else if (k + 1 == day) { //当天
              nowData = {
                year: yearList[i],
                month: months,
                day: '今天',
                date: yearList[i] + "" + months + days,
                selected: 1, //当天
                re: yearList[i] + "-" + months + "-" + days,
                dd: '今天',
                price: '',
                isCheckRoom: true,
                isPriceStyle: 1
              }
              this.setData({
                getDate: yearList[i] + "-" + months + "-" + days
              })

            } else { //过期时间
              nowData = {
                year: yearList[i],
                month: months,
                day: k + 1,
                date: yearList[i] + "" + months + days,
                selected: 3, //无效日期
                re: yearList[i] + "-" + months + "-" + days,
                dd: k + 1,
                price: '',
                isCheckRoom: true,
                isPriceStyle: 1
              }
            }
            dataMonth.push(nowData)
            if (k == 0) {
              let date = new Date(yearList[i] + "-" + months + "-" + k + 1)
              let weekss = date.getDay() //获取每个月第一天是周几
              weeks.push(weekss)
            }
          } else { //其他情况
            nowData = { //组装自己需要的数据
              year: yearList[i],
              month: months,
              day: k + 1,
              date: yearList[i] + "" + months + days,
              selected: 0,
              re: yearList[i] + "-" + months + "-" + days,
              dd: k + 1,
              price: '',
              isCheckRoom: true,
              isPriceStyle: 1
            }
            dataMonth.push(nowData)
            if (k == 0) {
              let date = new Date(yearList[i] + "-" + months + "-" + k + 1)
              let weekss = date.getDay() //获取每个月第一天是周几
              weeks.push(weekss)
            }
          }
          console.log('dd:' + nowData.re)

        }
        dataAll.push(dataMonth)

      }
    }

    for (let i = 0; i < dataAll.length; i++) {
      if (dataAll[i].length != 0) {
        dataAll2.push(dataAll[i]);
      }
      console.log(dataAll2[i])
    }
    this.setData({
      date: dataAll2,
      weeks: weeks
    })
  },
  /**
   * 入住日期回传
   */
  dateSelected: function() {
    var that = this
    var date = this.data.date
    var start = startDate.split('-')
    var end = endDate.split('-')
    var today = this.data.getDate.split('-')

    var tMonth = parseInt(today[1]) //当天月份

    var monthStart = parseInt(start[1]) //选择月份开始
    var monthEnd = parseInt(end[1]) //选择月份结束

    var dayStart = parseInt(start[2]) //选择日开始
    var dayEnd = parseInt(end[2]) //选择日结束

    var inn = false

    var monthStartIndex = 0 // 选择日期开始
    var monthEndIndex = 0 //选择日期结束
    if (monthStart >= tMonth) { //同一年日历
      monthStartIndex = monthStart - tMonth
    } else {
      monthStartIndex = monthStart + 12 - tMonth
    }

    if (monthEnd >= tMonth) {
      monthEndIndex = monthEnd - tMonth
    } else {
      monthEndIndex = 12 - tMonth + monthEnd
    }

    for (var i = monthStartIndex; i <= monthEndIndex; i++) {
      var days = date[i]
      var dayEndIndex = days.length
      if (i == monthEndIndex) { //最后一个月的日期
        dayEndIndex = dayEnd - 1
      } else {
        dayEndIndex = days.length - 1
      }

      var dayStartIndex = 0
      if (i == monthStartIndex) {
        dayStartIndex == dayStart - 1
      } else {
        dayStartIndex = 0
      }
      console.log('日历 dateSelected   :  ' + i + '  ------  ' + startDate + "   :    " + endDate)
      console.log(' dateSelected : ' + monthStartIndex + '   :  ' + monthEndIndex + '    :    ' + dayStartIndex + '   :   ' + dayEndIndex)
      for (var j = dayStartIndex; j <= dayEndIndex; j++) {
        var selected = 'date[' + i + '][' + j + '].selected'
        var day = 'date[' + i + '][' + j + '].day'
        var dd = days[j].day
        var ddnew = days[j].dd
        if (startDate == days[j].re && endDate == days[j].re && (this.data.isRoomList == 'false' || that.data.isReserve == 1)) {
          that.setData({
            [day]: '入-离',
            [selected]: 4
          })
        } else {
          if (startDate == days[j].re) {
            inn = true;
            if (this.data.isRoomList == 'false' || that.data.isReserve == 1) {
              that.setData({
                [day]: '入住'
              })
            } else {
              that.setData({
                [day]: ddnew
              })
            }
          }
          if (inn) {
            that.setData({
              [selected]: 4
            })
          }
          if (endDate == days[j].re) {
            inn = false;
            if (this.data.isRoomList == 'false' || that.data.isReserve == 1) {
              that.setData({
                [day]: '离开'
              })
            } else {
              that.setData({
                [day]: ddnew
              })
            }
            break;
          }
        }
      }
    }
  },
  /**
   * 清除选中
   */
  clearSlected() {
    var date = this.data.date
    var start = startDate.split('-')
    var end = endDate.split('-')
    var today = this.data.getDate

    var tMonth = parseInt(today.split('-')[1]) //当天月份

    var monthStart = parseInt(start[1]) //选择月份开始
    var monthEnd = parseInt(end[1]) //选择月份结束

    var dayStart = parseInt(start[2]) //选择日开始
    var dayEnd = parseInt(end[2]) //选择日结束

    var inn = false

    var monthStartIndex = 0 // 选择日期开始
    var monthEndIndex = 0 //选择日期结束
    if (monthStart >= tMonth) { //同一年日历
      monthStartIndex = monthStart - tMonth
    } else {
      monthStartIndex = monthStart + 12 - tMonth
    }

    if (monthEnd >= tMonth) {
      monthEndIndex = monthEnd - tMonth
    } else {
      monthEndIndex = 12 - tMonth + monthEnd
    }

    var inn = false
    var sel = 0
    for (var i = monthStartIndex; i <= monthEndIndex; i++) {
      var days = date[i]

      var dayStartIndex = (i == monthStartIndex) ? dayStart - 1 : 0

      var dayEndIndex = days.length
      if (i == monthEndIndex) { //最后一个月的日期
        dayEndIndex = dayEnd - 1
      } else {
        dayEndIndex = days.length - 1
      }

      console.log('日历clearSlected    :  ' + i + "   :  " + startDate + "   :    " + endDate)
      console.log(' clearSlected ：' + monthStartIndex + '   :  ' + monthEndIndex + '    :    ' + dayStartIndex + "   ???    " + dayStart + '   :   ' + dayEndIndex)

      for (var j = dayStartIndex; j <= dayEndIndex; j++) {
        var dd = days[j].day + ''
        var ddnew = days[j].dd
        console.log('ddNea : ' + ddnew)
        var rr = days[j].re
        var selected = 'date[' + i + '][' + j + '].selected'
        var re = 'date[' + i + '][' + j + '].re'
        var day = 'date[' + i + '][' + j + '].day'
        if (days[j].selected == 3) {
          sel = 3
        } else if (days[j].re == today) {
          sel = 1
        } else {
          sel = 0
        }
        this.setData({
          [selected]: sel
        })
        if (this.data.isRoomList == 'false' || this.data.isReserve == 1) {
          console.log("11111 :" + dd)
          if (dd == '入住' || dd == '离开' || dd == '入-离') {
            if (rr == today) {
              console.log("3333 :" + (dd))
              this.setData({
                [day]: '今天'
              })
            } else {
              console.log("2222 :" + (dd))
              this.setData({
                [day]: parseInt(rr.split('-')[2])
              })
            }
          } else if (rr == today) {
            console.log("3333 :" + (dd))
            this.setData({
              [day]: '今天'
            })
          } else {
            console.log("4444 :" + (dd))
            this.setData({
              [day]: dd
            })
          }
        } else {
          console.log("5555 :" + ddnew)
          this.setData({
            [day]: ddnew
          })
        }
      }
    }
  },
  clearbtn: function(e) {
    this.clearSlected();
    var pages = getCurrentPages()
    var curPage = pages[pages.length - 1]
    var prePage = pages[pages.length - 2]
    prePage.setData({
      dateType: '入住日期',
      startTime: '',
      endTime: '',
      bingPage: 1,
      messageCode: "",
      list: null,
      isGetData: false,
      iss: true
    })
    prePage.connectNetForData()
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 价格日历选择 
   */
  PriceCalendarSelected: function(e) {
    console.log('PriceCalendarSelected :  ' + this.data.date)
    if (con == 0) {
      this.clearSlected();
    }
    var isSelectedPrice = false
    var indexMonth = e.currentTarget.dataset.index
    var indexDay = e.currentTarget.dataset.indexs
    var isSelcted = this.data.date[indexMonth][indexDay].selected
    console.log(this.data.date[indexMonth][indexDay])
    console.log('dd : ' + isSelcted)
    var overnight = this.data.overnight
    con = con + 1
    var select = 4
    var selected = 'date[' + indexMonth + '][' + indexDay + '].selected'
    var dayTip = 'date[' + indexMonth + '][' + indexDay + '].day'
    var re = this.data.date[indexMonth][indexDay].re
    var selDaysInt = 0 // 选择日期天数
    if (isSelcted != 3 && this.data.date[indexMonth][indexDay].isCheckRoom) { //可以入住
      if (!isCheckIn) {
        isCheckIn = true
        isCheckOut = true
        checkInIndexMonth = indexMonth
        checkInIndexDay = indexDay
        checkInRe = re
        startDate = re
        selDaysInt = selDaysInt + 1
        this.setData({
          [selected]: select,
          [dayTip]: '入住'
        })
      }
      var isChhh = true
      if (overnight == 1) { //过夜
        if (re == checkInRe) {
          isChhh = false
        }
      } else { //不过夜
        isChhh = true
      }

      var istrue = false //是否日期选择有效
      if (checkInIndexMonth < indexMonth && isChhh) {
        istrue = true;
      } else if (checkInIndexMonth == indexMonth && checkInIndexDay <= indexDay && isChhh) {
        istrue = true;
      } else {
        istrue = false;
      }

      if (istrue && isCheckOut && con > 1) {
        if (checkInIndexMonth == indexMonth && checkInIndexDay == indexDay) { //入住离店
          var selects = 4
          var sel = 'date[' + indexMonth + '][' + indexDay + '].selected'
          var dayT = 'date[' + indexMonth + '][' + indexDay + '].day'
          endDate = re
          this.setData({
            [sel]: selects,
            [dayTip]: '入-离'
          })
          isCheckIn = false
          con = 0
          var pages = getCurrentPages()
          var curPage = pages[pages.length - 1]
          var prePage = pages[pages.length - 2]
          var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
          prePage.setData({
            checkInDate: timeChange.dateToString(checkInDate),
            checkOutDate: timeChange.dateToString(checkInDate),
            checkDays: '共1天',
            startTime: startDate,
            endTime: endDate,
            isShowTip: true
          })
          prePage.connectNetForData()
          wx.navigateBack({
            delta: 1
          })
        } else {
          for (var i = checkInIndexMonth; i <= indexMonth; i++) { //月份的遍历
            var jj
            if (i == checkInIndexMonth) {
              jj = checkInIndexDay
            } else {
              jj = 0
            }
            endDate = re
            for (var j = jj; j < this.data.date[i].length; j++) { //日的遍历
              selDaysInt = selDaysInt + 1
              var isCheckRoom = this.data.date[i][j].isCheckRoom
              var selects = 4
              var sel = 'date[' + i + '][' + j + '].selected'
              var dayT = 'date[' + i + '][' + j + '].day'

              if (!isCheckRoom) {
                isSelectedPrice = true
              }

              if (isSelectedPrice) {
                con == 0
                isCheckIn = false
                this.clearSlected()
                break
              }

              if (i == indexMonth && j == indexDay) {
                this.setData({
                  [sel]: selects,
                  [dayTip]: '离开'
                })
                isCheckIn = false
                con = 0
                var pages = getCurrentPages()
                var curPage = pages[pages.length - 1]
                var prePage = pages[pages.length - 2]
                var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
                var checkOutDate = this.data.date[i][j].re
                if (overnight == 1) { //过夜
                  selDaysInt = selDaysInt - 1
                }
                prePage.setData({
                  checkInDate: timeChange.dateToString(checkInDate),
                  checkOutDate: timeChange.dateToString(checkOutDate),
                  checkDays: '共' + selDaysInt + '天',
                  startTime: startDate,
                  endTime: endDate,
                  isShowTip: true
                })
                prePage.connectNetForData()
                wx.navigateBack({
                  delta: 1
                })
                break
              } else {
                this.setData({
                  [sel]: selects
                })
              }
            }
          }
        }
      }


    }
  },

  /**
   * 日期选择 
   */
  selectday: function(e) {
    if (this.data.isReserve == 0) { //非价格日历
      this.calendarSelect(e)

    } else { //价格日历
      this.PriceCalendarSelected(e)
    }
  },
  /**
   * 无价格日期选择
   */
  calendarSelect: function(e) {
    console.log(this.data.date)
    if (con == 0) {
      this.clearSlected();
    }
    console.log(e)
    var indexMonth = e.currentTarget.dataset.index
    var indexDay = e.currentTarget.dataset.indexs
    var isSelcted = this.data.date[indexMonth][indexDay].selected
    var re = this.data.date[indexMonth][indexDay].re
    console.log(this.data.date[indexMonth][indexDay])
    console.log('dd : ' + isSelcted)
    if (isSelcted != 3) {
      con = con + 1
      var select = 4
      var selected = 'date[' + indexMonth + '][' + indexDay + '].selected'
      var dayTip = 'date[' + indexMonth + '][' + indexDay + '].day'
      if (!isCheckIn && this.data.isRoomList == 'false') {
        isCheckIn = true
        isCheckOut = true
        checkInIndexMonth = indexMonth
        checkInIndexDay = indexDay
        startDate = re
        this.setData({
          [selected]: select,
          [dayTip]: '入住'
        })
      }
      if (!isCheckIn && this.data.isRoomList == 'true') {
        isCheckIn = true
        isCheckOut = true
        checkInIndexMonth = indexMonth
        checkInIndexDay = indexDay
        startDate = re
        this.setData({
          [selected]: select
        })
      }
      var istrue = false
      if (checkInIndexMonth < indexMonth) {
        istrue = true;
      } else if (checkInIndexMonth == indexMonth && checkInIndexDay <= indexDay) {
        istrue = true;
      } else {
        istrue = false;
      }

      if (istrue) {
        if (isCheckOut && this.data.isRoomList == 'false') {
          if (checkInIndexMonth == indexMonth && checkInIndexDay == indexDay && con > 1) {
            var selects = 4
            var sel = 'date[' + indexMonth + '][' + indexDay + '].selected'
            var dayT = 'date[' + indexMonth + '][' + indexDay + '].day'
            endDate = re
            this.setData({
              [sel]: selects,
              [dayTip]: '入-离'
            })
            isCheckIn = false
            con = 0
            var pages = getCurrentPages()
            var curPage = pages[pages.length - 1]
            var prePage = pages[pages.length - 2]
            var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
            prePage.setData({
              checkInOutDate: checkInDate + '至' + checkInDate,
              colorCheck: 'rgb(51,51,51)',
              startTime: checkInDate,
              endTime: checkInDate
            })

            wx.navigateBack({
              delta: 1
            })
          } else if (con > 1) {
            console.log('checkInIndexMonth : ' + checkInIndexMonth)
            console.log('checkInIndexDay')
            for (var i = checkInIndexMonth; i <= indexMonth; i++) { //月份的遍历
              var jj
              if (i == checkInIndexMonth) {
                jj = checkInIndexDay
              } else {
                jj = 0
              }
              for (var j = jj; j < this.data.date[i].length; j++) { //日的遍历
                var selects = 4
                var sel = 'date[' + i + '][' + j + '].selected'
                var dayT = 'date[' + i + '][' + j + '].day'
                endDate = re
                if (i == indexMonth && j == indexDay) {
                  this.setData({
                    [sel]: selects,
                    [dayTip]: '离开'
                  })
                  isCheckIn = false
                  con = 0
                  var pages = getCurrentPages()
                  var curPage = pages[pages.length - 1]
                  var prePage = pages[pages.length - 2]
                  var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
                  var checkOutDate = this.data.date[i][j].re
                  prePage.setData({
                    checkInOutDate: checkInDate + '至' + checkOutDate,
                    colorCheck: 'rgb(51,51,51)',
                    startTime: checkInDate,
                    endTime: checkOutDate
                  })

                  wx.navigateBack({
                    delta: 1
                  })
                } else {
                  this.setData({
                    [sel]: selects
                  })
                }
              }
            }
          }
        }

        if (isCheckOut && this.data.isRoomList == 'true') {
          if (checkInIndexMonth == indexMonth && checkInIndexDay == indexDay && con > 1) {
            var selects = 4
            var sel = 'date[' + indexMonth + '][' + indexDay + '].selected'
            this.setData({
              [sel]: selects
            })
            isCheckIn = false
            con = 0
            var pages = getCurrentPages()
            var curPage = pages[pages.length - 1]
            var prePage = pages[pages.length - 2]
            var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
            var mm = checkInDate.split('-')
            console.log(mm)
            prePage.setData({
              dateType: mm[1] + '.' + mm[2] + '-' + mm[1] + '.' + mm[2],
              startTime: checkInDate,
              endTime: checkInDate,
              bingPage: 1,
              list: null,
              messageCode: "",
              isGetData: false,
              iss: true
            })
            prePage.connectNetForData()
            wx.navigateBack({
              delta: 1
            })
          } else if (con > 1) {
            for (var i = checkInIndexMonth; i <= indexMonth; i++) { //月份的遍历
              var jj
              if (i == checkInIndexMonth) {
                jj = checkInIndexDay
              } else {
                jj = 0
              }
              for (var j = jj; j < this.data.date[i].length; j++) { //日的遍历
                var selects = 4
                var sel = 'date[' + i + '][' + j + '].selected'
                if (i == indexMonth && j == indexDay) {
                  this.setData({
                    [sel]: selects,
                  })
                  isCheckIn = false
                  con = 0
                  var pages = getCurrentPages()
                  var curPage = pages[pages.length - 1]
                  var prePage = pages[pages.length - 2]
                  var checkInDate = this.data.date[checkInIndexMonth][checkInIndexDay].re
                  var checkOutDate = this.data.date[i][j].re
                  var mm = checkInDate.split('-')
                  var dd = checkOutDate.split('-')
                  prePage.setData({
                    dateType: mm[1] + '.' + mm[2] + '-' + dd[1] + '.' + dd[2],
                    startTime: checkInDate,
                    endTime: checkOutDate,
                    bingPage: 1,
                    messageCode: "",
                    list: null,
                    isGetData: false,
                    iss: true
                  })
                  prePage.connectNetForData()
                  wx.navigateBack({
                    delta: 1
                  })
                } else {
                  this.setData({
                    [sel]: selects
                  })
                }
              }
            }
          }
        }
      }
    }
  }
})